local PLUGIN = exsto.CreatePlugin()

PLUGIN:SetInfo({
	Name = "LuaDev Interface",
	ID = "luadev-interface",
	Desc = "Interfaces Exsto with Python1320's LuaDev addon.",
	Owner = "Prefanatic",
} )

if !luadev then require( "luadev" ) end

function PLUGIN:Init()
	print( "I am happy!" )
end

function PLUGIN:ExecuteServer( caller, filepath )
	if !luadev then
		return { caller, COLOR.NORM, "Unable to access ", COLOR.NAME, "LuaDev library!" }
	end
	
	local data = file.Read( "../lua/" .. filepath )
	if !data then 
		return { caller, COLOR.NORM, "Error reading ", COLOR.NAME, filepath, COLOR.NORM, ".  File doesn't exist." }
	end
	
	luadev.RunOnServer( data, filepath )
	
	return { COLOR.NAME, caller:Nick(), COLOR.NORM, " is executing on the server: ", COLOR.NAME, filepath }
end
PLUGIN:AddCommand( "executeserver", {
	Call = PLUGIN.ExecuteServer,
	Desc = "Allows users to execute a lua file on the server.",
	Console = { "exec_server" },
	Chat = { "!exec_server" },
	ReturnOrder = "File",
	Args = { File = "STRING"},
	Category = "LuaDev",
})

function PLUGIN:ExecuteClient( caller, filepath )
	if !luadev then
		return { caller, COLOR.NORM, "Unable to access ", COLOR.NAME, "LuaDev library!" }
	end
	
	local data = file.Read( "../lua/" .. filepath )
	if !data then 
		return { caller, COLOR.NORM, "Error reading ", COLOR.NAME, filepath, COLOR.NORM, ".  File doesn't exist." }
	end
	
	luadev.RunOnClients( data, filepath )
	
	return { COLOR.NAME, caller:Nick(), COLOR.NORM, " is re-sending to the clients: ", COLOR.NAME, filepath }
end
PLUGIN:AddCommand( "executeclient", {
	Call = PLUGIN.ExecuteClient,
	Desc = "Allows users to resend and execute files to the client.",
	Console = { "send_clients" },
	Chat = { "!send_clients" },
	ReturnOrder = "File",
	Args = { File = "STRING"},
	Category = "LuaDev",
})

PLUGIN:Register()